<template>
  <div class="asnBill">
    <el-dialog
      title="转移SO到新的波次"
      :visible.sync="dialogTransVisible"
      :before-close="handleClose"
      width="500px"
      style="margin-top: -10vh"
    >
      <el-table
        highlight-current-row
        @current-change="handleSelChange"
        :data="WaveMasters"
        style="width: 100%"
      >
        <el-table-column fixed="left" type="index" width="55"></el-table-column>
        <el-table-column sortable prop="waveId" label="波次编码"></el-table-column>

        <el-table-column fixed="right" label="操作" width="150">
          <template slot-scope="scope">
            <el-button
              @click="transToWaveConfirm(scope.row.waveId)"
              type="edit"
              plain
              size="small"
            >转移至此波次</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog
      title="分配仓管员"
      :visible.sync="dialogAllocate"
      :before-close="handleClose2"
      width="500px"
      :close-on-click-modal="false"
    >
      <el-form>
        <el-select v-model="userId" filterable placeholder="请选择">
          <el-option
            v-for="item in users"
            :key="item.userId"
            :label="item.userName"
            :value="item.userId"
          ></el-option>
        </el-select>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogAllocate = false">取 消</el-button>
        <el-button type="primary" @click="commitAllocateUser()">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="修改备注"
      :visible.sync="dialogAllocate2"
      :before-close="handleClose2"
      width="500px"
      :close-on-click-modal="false"
    >
      <el-form>
        <el-input placeholder="请输入备注" v-model="rowData.remake" type="text" clearable></el-input>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogAllocate2 = false">取 消</el-button>
        <el-button type="primary" @click="updateWave()">确 定</el-button>
      </div>
    </el-dialog>

    <div class="publicSearch">
      <!--        <div class="searchBar"></div>-->

      <div class="searchBar" :style="{ height: isMoreSearch ? 'auto' : '' }">
        <el-button-group>
          <el-button @click="getWaveMasterData()" size="mini" icon="el-icon-search">查询</el-button>
        </el-button-group>
        <div>
          <span>波次查询</span>
          <el-input
            v-model="searchData.keyWords"
            size="mini"
            style="width:160px"
            placeholder="波次/履约号/物料"
            clearable
          ></el-input>
        </div>

        <el-button-group style="margin-left: 90px">
          <el-button @click="getWaveDetailData" size="mini" icon="el-icon-search">查询</el-button>
          <el-button @click="clearSearchData" size="mini" icon="el-icon-refresh">重置</el-button>
        </el-button-group>
        <div>
          <span>物料</span>
          <el-input v-model="searchData2.keyWords" size="mini" placeholder="名称/编码" clearable></el-input>
        </div>
        <div>
          <span>发料属性</span>
          <el-input v-model="searchData2.feedCategory" size="mini" placeholder="请输入" clearable></el-input>
        </div>

        <div>
          <span>状态</span>
          <el-select v-model="searchData2.state" size="mini" filterable placeholder="请选择" clearable>
            <el-option
              v-for="state in states"
              :key="state.value"
              :value="state.value"
              :label="state.label"
            ></el-option>
          </el-select>
        </div>
        <div>
          <el-button @click="diaLogRemake" size="mini" icon="el-icon-refresh">修改备注</el-button>
        </div>
      </div>
    </div>

    <div class="headerBtns"></div>

    <div class="tableBox organizationLeftTab" style="width: 20%">
      <el-table
        id="divContainer"
        ref="waveTable"
        highlight-current-row
        @current-change="handleSelChange"
        v-loading="loading.parent"
        :data="WaveMasters"
        style="width: 100%"
      >
        <el-table-column sortable prop="code" label="配料单">
          <template slot-scope="scope">
            <el-card class="box-card" style="margin-right: 25px">
              <div slot="header" class="clearfix">
                <span>{{ scope.row.code }}</span>

                <!-- <el-button  style="float: right; padding: 3px 0"  type="text" @click="showTransWaveModal">分配  </el-button> -->
                <!-- <el-button @click="deleteWaveConfirm(scope.row.waveId)" style="float: right; padding: 3px 0" type="text">删除</el-button> -->
              </div>

              <div v-if="scope.row.state != null">
                状态：
                <span style="color: #f56c6c" v-if="scope.row.state == 0">新建</span>
                <span style="color: #8b3a62" v-if="scope.row.state == 1">执行中</span>
                <span style="color: #67c23a" v-if="scope.row.state == 8">已完成</span>
              </div>
              <div>生成时间：{{ scope.row.createTime }}</div>
              <div>分配人：{{ scope.row.allotUserName }}</div>

              <div v-if="scope.row.totalSkuCount != null">
                生产任务单总数：{{ scope.row.totalBillCount }}
                <!-- /{{
                  scope.row.soCountLimit
                }}-->
              </div>
              <div v-if="scope.row.totalSkuCount != null">
                物料行数：{{ scope.row.totalSkuCount }}
                <!-- /{{ scope.row.itemCount }} -->
              </div>

              <div v-if="scope.row.totalSkuCount != null">
                备注：{{ scope.row.remake }}
                <!-- /{{ scope.row.itemCount }} -->
              </div>
            </el-card>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        style="text-align: right"
        class="pagination-bottom"
        @current-change="handleCurrentChange"
        :current-page.sync="searchData.pageNum"
        :page-size="searchData.pageSize"
        @size-change="handleSizeChange"
        :page-sizes="[15, 30, 50, 100]"
        layout="sizes,total, prev, pager, next  "
        :total="searchData.total"
      ></el-pagination>
    </div>
    <div class="organizationMiddle">
      <!--  <i class="el-icon-d-arrow-right"></i> -->
    </div>
    <div class="tabs organizationRight" style="width: 77%">
      <el-tabs
        class="tabs organizationRight"
        style="width: 100%"
        type="border-card"
        tab-position="top"
        v-model="activeName"
      >
        <el-tab-pane label="明细信息" name="first">
          <div class="headerBtns">
            <el-button
              size="small"
              :disabled="mergeFlg"
              type="primary"
              round
              @click="allocateUser"
            >分配仓管员</el-button>

            <el-button size="small" type="info" round @click="allocateQty">大件预分配</el-button>

            <el-button
              size="small"

              type="primary"
              round
              @click="virtualLog"
            >直发虚仓出库</el-button>

<!--            <el-button size="small" :disabled="VMIFlg" type="primary" round @click="$router.push('/work/inventory/inventoryVmi')">VMI入库</el-button>-->
              <el-button size="small"  type="primary" round @click="findVmiList">VMI入库</el-button>
            <el-button size="small"  type="primary" round @click="startLog">先发配件出库</el-button>
<!--            <el-button size="small"  type="primary" round @click="onSoMaster">按单拣货分配</el-button>-->
            <el-button size="small" type="primary" round @click="split">合单拆分</el-button>
            <el-button size="small" type="primary" round @click="downLoad">导出</el-button>
<!--            <el-button-->
<!--              size="small"-->
<!--              type="primary"-->
<!--              round-->
<!--              class="rightFloat"-->
<!--              @click="syncCurrentData()"-->
<!--            >同步拉取</el-button>-->
          </div>
          <div class="tableBox">
            <el-table
              highlight-current-row
              v-loading="loading.child"
              border
              @expand-change="onChange"
              @selection-change="handleWaveDetailSelChange"
              :row-class-name="tableRowClassName"
              :data="WaveDetails"
              row-key="waveDetailId"
              height="calc(100% - 50px)"
              style="width: 100%"
            >
              <!-- <el-table-column fixed="left" type="index" width="50"> -->

              <!-- </el-table-column> -->
              <el-table-column fixed type="selection" width="55"></el-table-column>
              <el-table-column
                show-overflow-tooltip
                sortable
                fixed
                prop="state"
                label="状态"
                width="100"
              >
                <template slot-scope="scope">
                  <span v-if="scope.row.state == 0" style="color: #909399">待分配</span>
                  <span v-if="scope.row.state == 1" style="color: #f56c6c">部分分配</span>
                  <span v-if="scope.row.state == 2" style="color: #67c23a">完全分配</span>

                  <span v-if="scope.row.state == 4" style="color: #81ce65">已出库</span>
                  <span v-if="scope.row.state == 8" style="color: #67c23a">已完成</span>
                </template>
              </el-table-column>
              <el-table-column
                fixed
                sortable
                show-overflow-tooltip
                prop="itemCode"
                label="物料编码"
                width="150"
              ></el-table-column>
              <el-table-column
                fixed
                sortable
                show-overflow-tooltip
                prop="itemName"
                label="物料名称"
                width="150"
              ></el-table-column>
              <el-table-column
                fixed
                sortable
                show-overflow-tooltip
                prop="feedCategory"
                label="发料属性"
                width="150"
              ></el-table-column>

              <el-table-column fixed show-overflow-tooltip prop="quantity" label="数量" width="100"></el-table-column>

              <el-table-column
                fixed
                show-overflow-tooltip
                prop="invQty"
                sortable
                label="可用库存"
                width="100"
              ></el-table-column>

              <el-table-column fixed show-overflow-tooltip prop="allInQty" label="所有库存" width="100"></el-table-column>
              <el-table-column fixed type="expand" label="展开" width="80">
                <template slot-scope="props">
                  <el-table
                    highlight-current-row
                    :data="props.row.expandList"
                    style="width: 80%; margin-left: 10%"
                  >
                    <el-table-column show-overflow-tooltip prop="areaCode" label="库区编码" width="250"></el-table-column>
                    <el-table-column show-overflow-tooltip prop="areaName" label="库区名称" width="250"></el-table-column>
                    <el-table-column show-overflow-tooltip prop="quantity" label="数量" width="250"></el-table-column>
                  </el-table>
                </template>
              </el-table-column>
              <el-table-column
                  sortable
                  show-overflow-tooltip
                  prop="pickUserName"
                  label="库管员"
                  width="180"
              ></el-table-column>
<!--              <el-table-column-->
<!--                show-overflow-tooltip-->
<!--                prop="preAllottedQuantity"-->
<!--                label="预分配数量"-->
<!--                width="100"-->
<!--              ></el-table-column>-->
              <!-- <el-table-column
                show-overflow-tooltip
                prop="freezeQuantity"
                label="冻结库存"
                width="100"
              ></el-table-column>-->
              <el-table-column
                show-overflow-tooltip
                prop="allottedQuantity"
                label="分配数量"
                width="100"
              ></el-table-column>
              <el-table-column show-overflow-tooltip prop="pickQuantity" label="拣货数量" width="100"></el-table-column>
<!--              <el-table-column show-overflow-tooltip prop="xfQuantity" label="先发配件数量" width="110">-->
<!--                <template slot-scope="scope">-->
<!--                  <span v-if="scope.row.xfQuantity == 0">{{scope.row.xfQuantity}}</span>-->
<!--                  <span-->
<!--                    v-if="scope.row.xfQuantity > 0"-->
<!--                    style="color: #67c23a"-->
<!--                  >{{scope.row.xfQuantity}}</span>-->
<!--                </template>-->
<!--              </el-table-column>-->

<!--              <el-table-column show-overflow-tooltip prop="zfQuantity" label="直发虚仓数量" width="110">-->
<!--                <template slot-scope="scope">-->
<!--                  <span v-if="scope.row.zfQuantity == 0">{{scope.row.zfQuantity}}</span>-->
<!--                  <span-->
<!--                    v-if="scope.row.zfQuantity > 0"-->
<!--                    style="color: #67c23a"-->
<!--                  >{{scope.row.zfQuantity}}</span>-->
<!--                </template>-->
<!--              </el-table-column>-->

              <el-table-column show-overflow-tooltip prop="vmiQuantity" label="vmi数量" width="110">
                <template slot-scope="scope">
                  <span v-if="scope.row.vmiQuantity == 0">{{scope.row.vmiQuantity}}</span>
                  <span
                    v-if="scope.row.vmiQuantity > 0"
                    style="color: #67c23a"
                  >{{scope.row.vmiQuantity}}</span>
                </template>
              </el-table-column>

              <el-table-column
                show-overflow-tooltip
                prop="warehouseQcQuantity"
                label="合格未入库数量"
                width="120"
              ></el-table-column>

<!--              <el-table-column sortable show-overflow-tooltip prop="rob" label="红蓝字" width="100">-->
<!--                <template slot-scope="scope">-->
<!--                  <span>{{ scope.row.rob?"普通件":"返还件" }}</span>-->
<!--                </template>-->
<!--              </el-table-column>-->
              <!-- <el-table-column
                show-overflow-tooltip
                prop="packDescribe"
                label="单位"
                width="80"
              >
              </el-table-column>-->



            </el-table>
          </div>
          <div>

          </div>
        </el-tab-pane>
        <el-tab-pane :label="label" name="second" :disabled="isDs"></el-tab-pane>
      </el-tabs>


      <el-dialog
          :title="dialogLabel"
          :visible.sync="dialogNewVisible"
          :before-close="handleClose"
          width="500px"
          style="margin-top: -10vh"
      >
        <el-form>
          <el-input placeholder="请输入备注" v-model="vmiNumber" type="number" clearable></el-input>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="
            dialogNewVisible = false;
          ">取 消</el-button>
          <el-button type="primary" @click="vim">确 定</el-button>
        </div>
      </el-dialog>



      <el-dialog
        :title="dialogLabel"
        :visible.sync="dialogNewVisible"
        :before-close="handleClose"
        width="500px"
        style="margin-top: -10vh"
      >
        <el-form>
          <el-input placeholder="请输入预分配数量" v-model="vmiNumber" type="number" clearable></el-input>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="
            dialogNewVisible = false;
          ">取 消</el-button>
          <el-button type="primary" @click="vim">确 定</el-button>
        </div>
      </el-dialog>


      <el-dialog
          title="VMI入库"
          width="1700px"
          :visible.sync="dialogReviewVisibleVMI"
          :before-close="handleClose4"
      >
      <div style="width: 200px;margin-left: 600px">
        <el-input
            v-model="search"
            size="mini"
            placeholder="输入关键字搜索"/>
      </div>


      <div class="bigbox">
        <!-- 左侧框 -->
        <div class="table-container">
          <!-- 左侧表格 -->
          <el-table
              ref="dxgrid"
              :data="currentPageData
         .filter(data => !search || data.itemCode.toLowerCase().includes(search.toLowerCase()))"
              highlight-current-row
              height="100%"
              border
              @selection-change="leftArrChange"
              style="width: 100%; padding-left: 0"
          >
            <el-table-column fixed="left" type="selection" width="55"></el-table-column>

            <el-table-column fixed="left" prop="itemName" label="物料名称" show-overflow-tooltip>
              <template slot-scope="scope">
            <span
                class="textBtn"
                @click="
                $EventBus.$emit('showPublicModal', scope.row.itemCode, 'item')
              "
            >{{ scope.row.itemName }}</span>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="itemCode" label="物料编码">
              <template slot-scope="scope">
            <span
                class="textBtn"
                @click="
                $EventBus.$emit('showPublicModal', scope.row.itemCode, 'item')
              "
            >{{ scope.row.itemCode }}</span>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="asnBillNo" label="任务单号">

            </el-table-column>
            <el-table-column show-overflow-tooltip prop="cellCode" label="货位"></el-table-column>
            <el-table-column show-overflow-tooltip prop="boxCode" label="追踪号"></el-table-column>
            <el-table-column show-overflow-tooltip prop="batchName" label="批次">
              <template slot-scope="scope">
            <span
                class="textBtn"
                @click="
                $EventBus.$emit('showPublicModal', scope.row.batchId, 'batch')
              "
            >{{ scope.row.batchName }}</span>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="supplierName" label="供应商"></el-table-column>
            <el-table-column show-overflow-tooltip prop="quantity" label="数量">
              <template slot-scope="scope">
            <span style="color: black; font-weight: 900">
              {{
                Math.floor(
                    (scope.row.quantity / scope.row.transRatio) * 10000
                ) / 10000
              }}
            </span>
                <span style="font-size: 20%">（{{ scope.row.packDescribe }}）</span>
              </template>
            </el-table-column>

          </el-table>
        </div>
        <!-- 中间框 -->
        <div class="select-to-right">
          <div>
            <el-button  @click="turnRight"  icon="el-icon-arrow-right"></el-button>
          </div>
          <div>
            <el-button   @click="turnLeft"  icon="el-icon-arrow-left"></el-button>

          </div>
        </div>


        <!-- 右侧框 -->
        <div class="table-container">
          <!-- 右侧表格 -->
          <el-table ref="yxgrid" border :data="yxData" height="100%" @selection-change="rightArrChange"
                    style="width: 100%; padding-left: 0"
          >
            <el-table-column fixed="left" type="selection" width="55"></el-table-column>
<!--            <el-table-column-->
<!--                fixed="left"-->
<!--                prop="inventoryId"-->
<!--                label="库存ID"-->
<!--                width="80"-->
<!--                show-overflow-tooltip-->
<!--            ></el-table-column>-->
            <el-table-column fixed="left" prop="itemName" label="物料名称" show-overflow-tooltip>
              <template slot-scope="scope">
            <span
                class="textBtn"
                @click="
                $EventBus.$emit('showPublicModal', scope.row.itemCode, 'item')
              "
            >{{ scope.row.itemName }}</span>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="itemCode" label="物料编码">
              <template slot-scope="scope">
            <span
                class="textBtn"
                @click="
                $EventBus.$emit('showPublicModal', scope.row.itemCode, 'item')
              "
            >{{ scope.row.itemCode }}</span>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="cellCode" label="货位"></el-table-column>
            <el-table-column show-overflow-tooltip prop="boxCode" label="追踪号"></el-table-column>
            <el-table-column show-overflow-tooltip prop="batchName" label="批次">
              <template slot-scope="scope">
            <span
                class="textBtn"
                @click="
                $EventBus.$emit('showPublicModal', scope.row.batchId, 'batch')
              "
            >{{ scope.row.batchName }}</span>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="supplierName" label="供应商"></el-table-column>
            <el-table-column show-overflow-tooltip prop="quantity" label="可入库数量"></el-table-column>
            <el-table-column show-overflow-tooltip prop="asnBillNo" label="单号"></el-table-column>

            <el-table-column show-overflow-tooltip prop="newReturnQty" width="200" label="入库数量" >
              <template slot-scope="scope">
                <el-input-number
                    v-model="scope.row.newReturnQty"
                    controls-position="right"
                    :min="0"
                    :max="scope.row.quantity"
                    label="请输入数量"
                    size="small"
                    style="width: 90%"
                ></el-input-number>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="handleClose4">取 消</el-button>
          <el-button type="primary" @click="commitVmi">提 交</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";

export default {
  name: "WaveMaster",
  data() {
    return {
      states: [
        {
          value: 0,
          label: "待分配",
          color: "#F56C6C"
        },
        {
          value: 1,
          label: "部分分配",
          color: "#8B3A62"
        },
        {
          value: 2,
          label: "完全分配",
          color: "#543044"
        },
        {
          value: 4,
          label: "已出库",
          color: "#543044"
        },
        {
          value: 3,
          label: "部分出库",
          color: "#543044"
        },
        {
          value: 8,
          label: "已完成",
          color: "#67C23A"
        }
      ],
      search:'',
      isDs: true,
      isIndeterminate: true,
      dialogNewVisible: false,
      form: {
        checkedCities: [],
        agreementNo: "", // 履约号
        billNo: "", //任务单号--只需要将这个传到后台
        dictValue: "", //入库类型
        wareName: "", //仓库
        uda3: "", //车间部门
        detailList: "", //明细数据,
        areaCode: "", //库区信息
        cellCode: "" //库位信息
      },
      wareId: PF.getLocal("wareId", "number"),
      users: [],
      userId: "",
      checkAll: false,
      isMoreSearch: false,
      activeName: "first",
      areas: [],
      currentPageData:[],
      yxData: [], // 右侧表格数据
      leftArr: [], // 左侧选择的数据
      rightArr: [], // 右侧选择的数据
      dialogReviewVisibleVMI: false,
      searchData: {
        state: null,
        pageNum: 1,
        pageSize: 10,
        total: null,
        keyWords: "",
        wareId: PF.getLocal("wareId", "number")
      },
      searchData2: {
        feedCategory: "", //发料属性
        state: null,
        pageNum: 1,
        pageSize: 10,
        total: null,
        keyWords: "",
        wareId: PF.getLocal("wareId", "number")
      },
      childSearchData: {
        waveId: ""
      },
      pickTaskSearch: {
        pageNum: 1,
        pageSize: 10,
        total: null,
        waveId: "",
        wareId: PF.getLocal("wareId", "number")
      },
      expands: [],
      WaveMasters: [],
      WaveData: {},
      WaveDetails: [],
      pickTasks: [],

      formLabelWidth: "120px",

      asnUdfHs: [],
      organizations: [],
      suppliers: [],
      vmiNumber: "",
      waveSelection: [],
      waveDetailSelection: [],
      newWaveSelection: [],
      waveMasterId: "",
      waveDetailIds: [],
      rowData: [],
      dialogTransVisible: false,
      pushUrl: "",
      waveScheduleState: 0,
      cities: [],
      cityOptions: [],
      editCronVisible: false,
      cronExpression: "",
      jobId: null,
      dialogLabel: "",
      loading: {
        parent: false,
        child: false
      },

      // 控制分配的页面
      dialogAllocate: false,
      dialogAllocate2: false,
      dialogAllocateQty: null,
      waveCode: "",
      expandList: [],
      // 明细信息中带出任务单号
      label: ""
    };
  },
  computed: {
    ...mapState([]),
    // 先发配件，直发虚仓的要单独出
    //
    mergeFlg() {
      let newItem = [];
      this.waveDetailSelection.forEach(item => {
        if (item.state === 2 ||  item.zfQuantity > 0) {
          newItem.push(item);
        }
      });
      return [...new Set(newItem)].length > 0;
    }
  },


  methods: {
    downLoad() {
      window.open(localStorage.getItem("baseIpPort")+`/wms/jmreport/view/799496547741904896?code=`+this.waveCode,'_blank')
    },
    findVmiList() {
      IOT.getServerData("/inventorys/vmiList", "get", {pageSize:999}, ret => {

        if (ret.code === 200) {
          this.dialogReviewVisibleVMI = true;
          this.currentPageData = ret.rows;
        } else {
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });
    },

    vim() {
      IOT.showOverlay("保存中，请稍等...");
      let ids = [];
      console.log(this.waveDetailSelection, "this.waveDetailSelection");
      this.waveDetailSelection.forEach(item => {
        ids.push(item.waveDetailId);
      });
      let searchData = {
        ids: ids.join(","),
        vmiNumber: this.vmiNumber
        // oldCellCods : this.form.checkedCities.join(","),
        // cellCode: this.form.cellCode //库位信息
      };
      IOT.getServerData(this.pushUrl, "get", searchData, ret => {
        this.loading.table = false;
        if (ret.code === 200) {
          alert("入库成功");
          this.getWaveDetailData();
          this.dialogNewVisible = false;
          IOT.hideOverlay();
        } else {
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
          IOT.hideOverlay();
        }
      });
    },



    leftArrChange(val) {
      this.leftArr = val;
    },
    rightArrChange(val) {
      this.rightArr = val;
    },
    // 将右侧数据转到左边
    // 将右侧数据转到左边
    turnLeft(){
      // 将右侧选择的数据  进行循环遍历
      this.rightArr.forEach((item, index) => {
        // 将数据插入到左边
        this.currentPageData.push(item)
        //再将左侧的数据进行删除
        this.yxData.forEach((l, i) => {
          if (item.inventoryId === l.inventoryId){
            this.yxData.splice(i, 1)
          }
        })
      })
    },
    // 将左侧数据转到右边
    turnRight(){
      let supplierName = [];
      let allArr = [];
      allArr= allArr.concat(this.leftArr);
      allArr= allArr.concat(this.yxData);
      allArr.forEach((item,index)=>{
        supplierName.push(item.supplierName)
        }
      )
      if ([...new Set(supplierName)].length > 1) {
        alert("请选择相同供应商")
        return false;
      }
      // 将左侧选择的数据  进行循环遍历
      this.leftArr.forEach((item, index) => {
        item.newReturnQty=item.quantity
        // 将数据插入到右边
        console.log(item,"itasgagag")
        this.yxData.push(item)
        //再将左侧的数据进行删除
        this.currentPageData.forEach((l, i) => {
          if (item.inventoryId === l.inventoryId){
            this.currentPageData.splice(i, 1)
          }
        })
      });
    },
    virtualLog() {
      this.pushUrl = "/wave/virtual";
      this.dialogLabel = "直发虚仓出入库";
      this.dialogNewVisible = true;
      // this.getAreaData();
      // this.vmiCellCode(1111427);
    },
    startLog() {
      this.pushUrl = "/wave/start";
      this.dialogLabel = "先发配件出库";
      this.dialogNewVisible = true;
      // this.getAreaData();
      // this.vmiCellCode(1111427);
    },


    vmiCellCode(asnStockId) {
      let detailIds = [];
      let obj = this.waveDetailSelection;
      obj.forEach(item => {
        detailIds.push(item.waveDetailId);
      });

      IOT.getServerData(
        "/wave/findCode",
        "get",
        {
          ids: detailIds.join(","),
          asnStockId: asnStockId
        },
        ret => {
          if (ret.code === 200) {
            console.log(ret);
            this.cities = ret.rows;
            this.cityOptions = ret.rows;
          } else {
            IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
          }
        }
      );
    },
    getCellData() {
      let searchData = {
        areaCode: this.form.areaCode,
        pageNum: 1,
        pageSize: 999
      };
      IOT.getServerData("/cell/infos/list", "get", searchData, ret => {
        this.loading.table = false;
        if (ret.code === 200) {
          this.cells = ret.rows;
          this.form.cellCode = ret.rows[0].cellCode;
          console.log(ret.rows, "this.cellls");
          // console.log(ret.rows[0].cellCode)
        } else {
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });
    },


    tableRowClassName({ row, rowIndex }) {
      if (row.xfQuantity > 0) {
        return "success-row";
      }
      if (row.zfQuantity) {
        return "zf-row";
      }
      if (row.vmiQuantity > 0) {
        return "vmi-row";
      }

      //虚仓
      if (row.cellCode === "ZF01-01-01") {
        return "warning-row";
      }
      return "";
    },

    getUserName(userId) {
      this.users.forEach(user => {
        if (user.userId == userId) {
          return user.userName;
        }
      });
    },
    allotWave(waveMaster) {
      waveMaster.allotUserName = this.getUserName(waveMaster.allotUserId);
      IOT.getServerData("/wave/masters/update", "post", waveMaster, ret => {
        if (ret.code === 200) {
        } else {
          waveMaster.allotUserId = null;
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });
    },
    getUsers() {
      IOT.getServerData(
        "/ware/infos/findUserByWareId",
        "get",
        { wareId: this.wareId },
        ret => {
          if (ret.code === 200) {
            this.users = ret.rows;
            console.log(JSON.stringify(this.users));
          } else {
            IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
          }
        }
      );
    },

    handleCheckAllChange(val) {
      this.form.checkedCities = val ? this.cityOptions : [];
      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.cities.length;
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.cities.length;
    },

    showEditCron() {
      this.editCronVisible = true;
    },
    handleCronClose() {
      this.editCronVisible = false;
    },
    handleSizeChange(val) {
      this.searchData.pageSize = val;
      this.getWaveMasterData();
      this.getWaveDetailData();
      // this.getPickTaskData();
    },
    handleCurrentChange(val) {
      this.searchData.pageNum = val;
      this.getWaveMasterData();
      this.getWaveDetailData();
      // this.getPickTaskData();
    },
    handleChildCurrentChange(val) {
      this.pageNum = val;
      // this.getPickTaskData();
    },
    handleChildSizeChange(val) {
      this.searchData.pageSize = val;
    },
    handleSelChange(rowData) {
      this.rowData = rowData;
      this.label = rowData.ancestralOrderBillNo;
      this.waveCode = rowData.code;
      this.childSearchData.waveId = rowData.waveId;
      this.pickTaskSearch.waveId = rowData.waveId;
      this.WaveData = JSON.parse(JSON.stringify(rowData));
      this.waveMasterId = rowData.waveId;
      //同步拉取数据
      this.getWaveDetailData();

      // this.getPickTaskData();
    },

    handleNewWaveSelChange() {},
    handleWaveDetailSelChange(val) {
      this.waveDetailSelection = val;
    },
    clearSearchData() {
      this.searchData2.keyWords = "";
      this.searchData2.state = null;
      this.searchData2.feedCategory = null;
      this.searchData2.rob = null;
    },

    diaLogRemake() {
      console.log(this.rowData,'this.rowDatathis.rowDatathis.rowData')
      this.dialogAllocate2 = true;
    },
    getWaveMasterData() {
      this.loading.parent = true;
      IOT.getServerData("/wave/masters/list", "get", this.searchData, ret => {
        this.loading.parent = false;
        if (ret.code === 200) {
          this.WaveMasters = ret.rows;
          this.WaveData = ret.rows[0] || {};
          this.searchData.total = ret.total;
          this.searchData.pageNum = ret.pageNumber;
          if (ret.rows.length == 0) {
            this.loading.parent = false;
            return;
          }
          this.$refs.waveTable.setCurrentRow(ret.rows[0]);
          this.childSearchData.waveId = ret.rows[0].waveId;
          this.pickTaskSearch.waveId = ret.rows[0].waveId;
          this.label =  ret.rows[0].ancestralOrderBillNo;
          this.getWaveDetailData();
          // this.getPickTaskData();
        } else {
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });
    },
    getWaveDetailData() {
      IOT.showOverlay("");
      IOT.getServerData(
        "/wave/details/" + this.childSearchData.waveId,
        "get",
        this.searchData2,
        ret => {
          console.log(JSON.stringify(ret));
          if (ret.code === 200) {
            this.WaveDetails = ret.rows;
            IOT.hideOverlay();

          } else {
            IOT.hideOverlay();
          }
        }
      );
    },
    getPickTaskData() {
      this.loading.child = true;
      IOT.getServerData(
        "/pick/tasks/findByWaveMasterId",
        "get",
        this.pickTaskSearch,
        ret => {
          this.loading.child = false;
          if (ret.code === 200) {
            this.pickTasks = ret.rows;
            this.pickTaskSearch.total = ret.total;
            this.pickTaskSearch.pageNum = ret.pageNumber;
          }
        }
      );
    },

    onChange(item, expandedRows) {
      console.log("item:", item);
      console.log("expandedRows:", expandedRows);
      if (expandedRows.length) {
        this.expands = [];
        if (item.acceptRecordCode != null) {
          this.expands.push(item.acceptRecordCode);
        }
        IOT.getServerData(
          "/inventorys/area/stock",
          "get",
          { itemCode: item.itemCode },
          ret => {
            console.log("查询订单物料返回：", ret);
            if (ret.code === 200) {
              // waveDetailId
              // let idx = this.WaveDetails.findIndex(v => {
              //   return v.waveDetailId === item.waveDetailId
              // })
              // this.$set(this.WaveDetails[idx], 'expandList', ret.rows)
              item.expandList = ret.rows;
              console.log(item.expandList,'item.expandListitem.expandList')
            } else {
              IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
            }
          }
        );
      }
    },

    allocateUser() {
      console.log(this.waveDetailSelection, "this.waveDetailSelection");
      //需要判断 是否勾选了波次明细
      if (this.waveDetailSelection.length === 0) {
        IOT.tips("请先选择明细！", "error");
        return;
      }
      for (var i = 0; i < this.waveDetailSelection.length; i++) {
        if (this.waveDetailSelection[i].state === 2) {
          IOT.tips("不能选择完全分配的明细！", "error");
          return;
        }
      }

      this.dialogAllocate = true;
    },
    allocateQty() {
      this.dialogAllocate2 = true;
    },
    commitVmi() {
      IOT.getServerData(
          "/wave/inventoryVmi/",
          "post",
          this.yxData,
          ret => {
            IOT.hideOverlay();
            if (ret.code === 200) {
              IOT.tips("保存成功！", "success", 1000, () => {
                this.handleClose4();
                this.dialogReviewVisibleVMI = false;
                this.getWaveDetailData();
              });
            } else {
              IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
            }
          }
      );
    },
    //分配提交
    commitAllocateUser() {
      //校验是否选择了仓管员
      if (!this.userId) {
        IOT.tips("请先选择仓管员！", "error");
        return;
      }
      var ids = "";
      for (var i = 0; i < this.waveDetailSelection.length; i++) {
        if (i == this.waveDetailSelection.length - 1) {
          ids += this.waveDetailSelection[i].waveDetailId;
        } else {
          ids += this.waveDetailSelection[i].waveDetailId + ",";
        }
      }
      // alert(this.userId);
      IOT.showOverlay("保存中，请稍等...");
      IOT.getServerData(
        "/wave/details/suggest",
        "post",
        { ids: ids, userId: this.userId },
        ret => {
          IOT.hideOverlay();
          if (ret.code === 200) {
            IOT.tips("保存成功！", "success", 1000, () => {
              // that.getWaveMasterData();
              this.userId = "";
              this.dialogAllocate = false;
              this.getWaveDetailData();
            });
          } else {
            IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
          }
        }
      );
    },

    virtual() {
      let detailIds = [];
      let obj = this.waveDetailSelection;
      obj.forEach(item => {
        console.log(item, "item");
        detailIds.push(item.waveDetailId);
      });

      IOT.getServerData(
        "/transfer/virtual",
        "get",
        { detailIds: detailIds.join(",") },
        ret => {
          IOT.hideOverlay();
          if (ret.code === 200) {
            IOT.tips("保存成功！", "success", 1000, () => {
              this.dialogAllocateQty = null;
              this.dialogAllocate2 = false;
              this.getWaveDetailData();
            });
          } else {
            IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
          }
        }
      );
    },
    updateWave() {
      let that = this;
      IOT.showOverlay("保存中,请稍等...");
      IOT.getServerData("/wave/masters/update", "post",  this.rowData , ret => {
        IOT.hideOverlay();
        if (ret.code === 200) {
          IOT.tips("修改成功！", "success", 1000, () => {
            that.getWaveMasterData();
            that.getWaveDetailData();
          });
        } else {
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });

    },
    shoWCell() {
      this.form.cellCode = "";
      this.getCellData();
      // 取消禁用
      this.isCell = false;
    },

    deleteWaveConfirm(id) {
      this.$confirm("确认删除？")
        .then(_ => {
          this.deleteWave(id);
        })
        .catch(_ => {});
    },
    deleteWave(id) {
      let that = this;
      IOT.showOverlay("删除中，请稍等...");
      IOT.getServerData("/wave/masters/delete", "get", { id: id }, ret => {
        IOT.hideOverlay();
        if (ret.code === 200) {
          IOT.tips("删除成功！", "success", 1000, () => {
            that.getWaveMasterData();
            that.getWaveDetailData();
          });
        } else {
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });
    },

    isDelete(id) {
      this.$confirm("确认删除？")
        .then(_ => {
          this.deleteWaveDetail(id);
        })
        .catch(_ => {});
    },
    deleteWaveDetail(id) {
      let that = this;
      IOT.showOverlay("删除中，请稍等...");
      IOT.getServerData("/wave/details/delete", "get", { id: id }, ret => {
        IOT.hideOverlay();
        if (ret.code === 200) {
          IOT.tips("删除成功！", "success", 1000, () => {
            that.getWaveDetailData();
          });
        } else {
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });
    },
    generateWaves() {
      let that = this;
      IOT.showOverlay("生成中，请稍等...");
      IOT.getServerData(
        "/wave/masters/generateWaves",
        "get",
        { wareId: PF.getLocal("wareId", "number") },
        ret => {
          IOT.hideOverlay();
          if (ret.code === 200) {
            IOT.tips("生成成功！", "success", 1000, () => {
              that.getWaveMasterData();
            });
          } else {
            IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
          }
        }
      );
    },

    showTransWaveModal() {
      if (this.waveDetailSelection.length <= 0) {
        IOT.tips("请至少选择一个波次明细！", "error", 1000, () => {
          IOT.hideOverlay();
        });
        return false;
      }
      let list = PF.JSON(this.waveDetailSelection);
      let waveDetailIds = [];
      for (let i = 0; i < list.length; i++) {
        waveDetailIds.push(list[i].waveDetailId);
      }
      this.waveDetailIds = waveDetailIds;

      this.dialogTransVisible = true;
    },
    handleClose() {
      this.dialogTransVisible = false;
    },
    handleClose2() {
      this.dialogAllocate = false;
      this.dialogAllocate2 = false;
    },
    transToWaveConfirm(waveId) {
      this.$confirm("确认转移至此波次？")
        .then(_ => {
          this.transToWave(waveId);
        })
        .catch(_ => {});
    },
    transToWave(waveId) {
      IOT.showOverlay("转移中，请稍等...");
      IOT.getServerData(
        "/wave/masters/transToWave",
        "post",
        {
          waveId: waveId,
          waveDetailIds: this.waveDetailIds
        },
        ret => {
          IOT.hideOverlay();
          this.waveDetailSelection = [];
          this.waveDetailIds = [];
          if (ret.code === 200) {
            IOT.tips("保存成功！", "success");
            this.dialogTransVisible = false;
          } else {
            IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
          }
        }
      );
    },
    switchScheduledWaveTaskState() {
      let that = this;
      let state = this.waveScheduleState;
      IOT.getServerData(
        "/monitor/job/changeStatus",
        "post",
        { jobId: that.jobId, status: state },
        ret => {
          that.getWaveTaskState();
          if (ret.code === 200) {
          } else {
            IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
          }
        }
      );
    },
    getWaveTaskState() {
      IOT.getServerData(
        "/monitor/job/list",
        "get",
        {
          methodName: "waveParams",
          methodParams: PF.getLocal("wareId", "number")
        },
        ret => {
          if (ret.code === 200) {
            this.waveScheduleState = ret.rows[0] ? ret.rows[0].status : 0;
            this.cronExpression = ret.rows[0] ? ret.rows[0].cronExpression : "";
            this.jobId = ret.rows[0] ? ret.rows[0].jobId : null;
          } else {
            IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
          }
        }
      );
    },
    handleClose4(done) {
      this.currentPageData = [];
      this.yxData = [];
      this.leftArr = [];
      this.rightArr = [];
      this.dialogReviewVisibleVMI = false;
    },
    syncCurrentData() {
      IOT.showOverlay("同步中，请稍等...");
      IOT.getServerData(
        "/wave/details/sync/data",
        "get",
        {
          waveCode: this.waveCode
        },
        ret => {
          if (ret.code === 200) {
            IOT.hideOverlay();
            this.getWaveMasterData();
          } else {
            IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
            IOT.hideOverlay();
          }
        }
      );
    },

    commitCronUpdate() {
      let that = this;
      IOT.showOverlay("保存中~~~");
      IOT.getServerData(
        "/monitor/job/updateCron",
        "post",
        { jobId: that.jobId, cronExpression: that.cronExpression },
        ret => {
          IOT.hideOverlay();
          if (ret.code === 200) {
            IOT.tips(ret.message || "保存成功！");
            that.getWaveTaskState();
            that.editCronVisible = false;
          } else {
            IOT.tips(ret.message || "server error!", "error");
          }
        }
      );
    },
    // 先发配件出库
    xfCk() {
      // 当前选中的数据--只能选中一个
      let obj = this.waveDetailSelection[0];
      //校验是否填写了数量
      if (obj.xfQuantity < 1 || this.waveDetailSelection.length > 1) {
        IOT.tips("物料不能先发配件出库", "error");
        return;
      }
      let ids = obj.waveDetailId;

      let searchData = {
        ids: ids.join(","),
        vmiNumber: this.vmiNumber
      };

      IOT.showOverlay("保存中，请稍等...");
      IOT.getServerData(
        "/wave/start/",
        "get",
          searchData,
        ret => {
          IOT.hideOverlay();
          if (ret.code === 200) {
            IOT.tips("保存成功！", "success", 1000, () => {
              this.dialogAllocateQty = null;
              this.dialogAllocate2 = false;
              this.getWaveDetailData();
            });``
          } else {
            IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
          }
        }
      );
    },

    //合单拆分
    split() {

      IOT.showOverlay("保存中，请稍等...");
      IOT.getServerData(
        "/wave/masters/split/"+this.waveCode,
        "get",
        null,
        ret => {
          IOT.hideOverlay();
          if (ret.code === 200) {
            IOT.tips("保存成功！", "success", 1000, () => {
              this.dialogAllocateQty = null;
              this.dialogAllocate2 = false;
              this.getWaveDetailData();
            });
          } else {
            IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
          }
        }
      );
    }
  },
  created() {
    this.getUsers();
    this.getWaveMasterData();
  },
  mounted() {}
};
</script>

<style scoped lang="less">
#divContainer {
  //height: 900px;
  //overflow: auto;
}

#divContainer::-webkit-scrollbar {
  border-width: 1px;
}
.detailItemBox {
  display: inline-block;
  margin-top: 20px;
  width: 300px;
  span {
    flex: 1;
  }
}
.current-row {
  .el-button--text {
    color: white;
  }
  .el-card {
    background-color: #409eff;
    color: white;
  }
}
</style>

<style>
.el-table .warning-row {
  background: #fae5cb;
}
.el-table .success-row {
  background: rgba(94, 180, 134, 0.53);
}
.el-table .zf-row {
  background: #ecb6ab;
}
.el-table .vmi-row {
  background: #85d754;
}
.bigbox {
  height: 500px;
  display: flex;
  justify-content: flex-start;
}
.table-container{
  width: 800px;
}
</style>
